<template>
    <div class="container">
        <!-- 顶部导航栏 -->
        <el-header>
            <div class="topbar">
                <span class="shop-list" style="margin-left: 600px">商家列表</span>
                <span class="username" style="margin-left: 500px">用户：{{customer.customerName}}</span>
                <el-button type="primary" @click="toHistory">历史订单</el-button>
            </div>
        </el-header>

        <!-- 主体内容 -->
        <el-main>
            <el-row>
                <!-- 使用 v-for 循环遍历商家数据，并使用 el-card 显示 -->
                <el-col :span="4" v-for="shop in shops" :key="shop.shopId">
                    <el-card class="shop-card" @click="toItem(shop.shopId)">
                        <img :src="shop.shopImg" class="shop-img" :alt="shop.shopName">
                        <div slot="header" class="shop-name">{{ shop.shopName }}</div>
                    </el-card>
                </el-col>
            </el-row>
        </el-main>
    </div>
</template>

<script setup>
import {onMounted, ref} from 'vue';
import {getAllShop} from "@/api/shop";
import {getCustomerInfo} from "@/api/customer";
import {useRouter} from "vue-router";
import router from "@/router";
const shops=ref([])
const customer=ref({})
onMounted(async () => {
    let result = await getAllShop()
    shops.value=result.data
    let result2=await getCustomerInfo()
    customer.value=result2.data
})

function toItem(shopId){
    router.push({path:'/item',query:{shopId:shopId}})
}
function toHistory(){
    router.push('/historyOrder')
}
</script>

<style>
.container {
    width: 100%;
    height: 100vh;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
}

.shop-list {
    font-size: 24px;


}

.username {
    font-size: 18px;
}

.shop-card {
    margin: 10px;
}

.shop-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.shop-name {
    text-align: center;
}
</style>